package com.jjb.www.ui.adapter;

import android.content.Context;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;

import com.hjq.shape.view.ShapeImageView;
import com.hjq.shape.view.ShapeTextView;
import com.jjb.www.R;
import com.jjb.www.app.AppAdapter;
import com.jjb.www.http.api.PaymentListApi;

/**
 *    author : Android CRG
 *    github : https://github.com/getActivity/AndroidProject
 *    time   : 2018/11/05
 *    desc   : 可进行拷贝的副本
 */
public final class PayListAdapter extends AppAdapter<PaymentListApi.Bean> {

    public PayListAdapter(Context context) {
        super(context);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder();
    }

    private final class ViewHolder extends AppAdapter<?>.ViewHolder {
        private ShapeImageView mImgType;
        private ShapeTextView mTvTitle;
        private ShapeTextView mTvPrice;
        private ShapeTextView mTvOrderNumber;
        private ShapeTextView mTvPayType;
        private ShapeTextView mTvTime;
        private ShapeTextView mTvFpType;



        private ViewHolder() {
            super(R.layout.item_pay_list);
            mImgType = findViewById(R.id.img_type);
            mTvTitle = findViewById(R.id.tv_title);
            mTvPrice = findViewById(R.id.tv_price);
            mTvOrderNumber = findViewById(R.id.tv_order_number);
            mTvPayType = findViewById(R.id.tv_pay_type);
            mTvTime = findViewById(R.id.tv_time);
            mTvFpType = findViewById(R.id.tv_fp_type);
        }

        @Override
        public void onBindView(int position) {
            PaymentListApi.Bean bean = getItem(position);
            //图片样式 1-报名，2-会员，3-课程，4补考
            if (bean.getImg_type()==1){
                mImgType.setImageResource(R.mipmap.icon_pay_blue);
            }else if (bean.getImg_type()==2){
                mImgType.setImageResource(R.mipmap.icon_pay_org);
            }else if (bean.getImg_type()==3){
                mImgType.setImageResource(R.mipmap.icon_pay_red);
            }else {
                mImgType.setImageResource(R.mipmap.icon_pay_black);
            }

            mTvTitle.setText(bean.getOrder_type_name());
            mTvPrice.setText(bean.getPay_money()+"元");
            mTvOrderNumber.setText("订单编号："+bean.getOrder_number());
            mTvPayType.setText(bean.getPay_method_id());
            mTvTime.setText(bean.getCreate_time());
            //开票状态 0未开票 1开票中 2已开票 3已拒绝 4 已过期
            if (bean.getInvoice_status()==0){
                mTvFpType.getShapeDrawableBuilder().setSolidColor(ContextCompat.getColor(getContext(), R.color.color_3675FE)).intoBackground();
            }else if (bean.getInvoice_status()==1){
                mTvFpType.getShapeDrawableBuilder().setSolidColor(ContextCompat.getColor(getContext(), R.color.color_3675FE)).intoBackground();

            }else if (bean.getInvoice_status()==2){
                mTvFpType.getShapeDrawableBuilder().setSolidColor(ContextCompat.getColor(getContext(), R.color.color_1D9500)).intoBackground();

            }else if (bean.getInvoice_status()==3){
                mTvFpType.getShapeDrawableBuilder().setSolidColor(ContextCompat.getColor(getContext(), R.color.color_3675FE)).intoBackground();

            }else if (bean.getInvoice_status()==4){
                mTvFpType.getShapeDrawableBuilder().setSolidColor(ContextCompat.getColor(getContext(), R.color.color_C4C4C4)).intoBackground();

            }
        }
    }
}